package server.dao;

import cn.hutool.core.math.Money;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import server.model.entity.Account;
import server.model.entity.MoneyRecord;

import javax.transaction.Transactional;
import java.util.List;

/**
 * 创建人:    xvzhe
 * 创建时间:
 * 修改时间:
 * 版本:      v1.0
 */
public interface MoneyRecordDao extends JpaRepository<MoneyRecord, String> {
    MoneyRecord findByIndentOrder(String indentOrder);

    MoneyRecord findByDyOrder(String dyOrder);

    @Modifying
    @Query(value = "update money_record set status = 'ERROR' where UNIX_TIMESTAMP(create_time) < ?1", nativeQuery = true)
    Integer upStatus(Long time);

    @Query(value = "select * from money_record where status = 'ING'  AND UNIX_TIMESTAMP(create_time) >= ?1", nativeQuery = true)
    List<MoneyRecord> findIng(Long time);

    @Query(value = "select * from money_record where create_time between current_date() and date_format(current_date,'%Y-%m-%d 23:59:59') AND STATUS = 'SUCCESS'", nativeQuery = true)
    List<MoneyRecord> findDay();

    @Query(value = "select * from money_record where create_time between current_date() and date_format(current_date,'%Y-%m-%d 23:59:59') AND system_code = ?1 ", nativeQuery = true)
    List<MoneyRecord> findDaySystem(String code);

    @Query(value = "select * from money_record where  system_code = ?1 ", nativeQuery = true)
    List<MoneyRecord> findSystem(String code);
}
